package servlet;

import java.io.IOException;
import java.sql.Connection;
import java.util.HashSet;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.sql.DataSource;

import pojo.Orders;
import service.OrdersManager;
import service.impl.OrdersManagerFactory;
import util.DButil;

/**
 * Servlet implementation class Buy
 */
public class Buy extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private OrdersManager manager;
	
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public Buy() {
        super();
        manager=OrdersManagerFactory.getInstance();
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		HashSet<Orders> oSet=(HashSet<Orders>)request.getSession().getAttribute("oset");
		DataSource ds=(DataSource)request.getServletContext().getAttribute("ds");
		Connection con=DButil.getConnection(ds);
		
		for (Orders o:oSet) {
			manager.addOrders(o, con);
		}
		
		DButil.close(con);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
